package com.ruoyi.monitor.controller;



import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.monitor.dao.entity.Camera;
import com.ruoyi.monitor.dto.domain.CameraRich;
import com.ruoyi.monitor.dto.req.CameraQueryReqDTO;
import com.ruoyi.monitor.service.CameraService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc: 监控设备管理
 *        一个设备可以有多个通道(摄像头)
 * @author：cc
 * @date: 2024/7/25
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/mon/camera")
public class CameraController {

    private final CameraService cameraService;

    @GetMapping("/detail/{id}")
    @ApiOperation(value = "查询设备详情", notes = "会把下面关联的管道也查出来")
    public AjaxResult detail(@PathVariable Long id) {
        CameraRich cameraRich = cameraService.queryById(id);
        return AjaxResult.success(cameraRich);
    }

    @GetMapping("/list")
    @ApiOperation(value = "列表查询", notes = "会把下面关联的管道也查出来")
    public AjaxResult list(CameraQueryReqDTO req, Pageable page) {
        // 设备列表查询, 会把底下关联的摄像头也查出来
        List<CameraRich> list = cameraService.queryList(req, page);
        return AjaxResult.success(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }

    @PostMapping("/add")
    @ApiOperation("添加设备")
    public AjaxResult add(@RequestBody Camera camera) {
        int res = cameraService.create(camera);
        return AjaxResult.success(res);
    }

    @PostMapping("/edit")
    @ApiOperation("编辑设备信息")
    public AjaxResult edit(@RequestBody Camera camera) {
        int res = cameraService.update(camera);
        return AjaxResult.success(res);
    }

    @PostMapping("/remove/{id}")
    @ApiOperation("删除设备")
    public AjaxResult remove(@PathVariable Long id) {
        int res = cameraService.remove(id);
        return AjaxResult.success(res);
    }

}
